View Javadoc

1   /**
2    * Copyright 2008 WebPhotos
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.webphotos.model;
17  
18  import java.util.Collection;
19  import java.util.Date;
20  import java.util.HashSet;
21  import java.util.Iterator;
22  
23  /**
24   * Builder for Entity AlbumVO
25   * @author Guilherme
26   */
27  public class AlbumVOBuilder {
28      
29      private String nmalbum;
30      private String descricao;
31      private Date dtInsercao;
32      private CategoryVO categoriasVO;
33      private HashSet<PhotoVO> photoVOs;
34      private Integer key;
35  
36      AlbumVOBuilder() {
37          photoVOs = new HashSet<PhotoVO>();
38          key = 0;
39      }
40  
41      AlbumVOBuilder(Integer key) {
42          this();
43          this.key = key;
44      }
45  
46      public AlbumVOBuilder withAlbumName(String nmalbum) {
47          this.nmalbum = nmalbum;
48          return this;
49      }
50  
51      public AlbumVOBuilder withDescription(String descricao) {
52          this.descricao = descricao;
53          return this;
54      }
55  
56      public AlbumVOBuilder withCreationDate(Date dtInsercao) {
57          this.dtInsercao = dtInsercao;
58          return this;
59      }
60  
61      public AlbumVOBuilder withCategory(CategoryVO categoriasVO) {
62          this.categoriasVO = categoriasVO;
63          return this;
64      }
65  
66      public AlbumVOBuilder withPhoto(PhotoVO photoVO) {
67          this.photoVOs.add(photoVO);
68          return this;
69      }
70  
71      public AlbumVOBuilder withPhotos(Collection<PhotoVO> photoVOs) {
72          this.photoVOs.addAll(photoVOs);
73          return this;
74      }
75  
76      public AlbumVO build() {
77          final AlbumVO albumVO = (key > 0 ? 
78                  new AlbumVO(key, nmalbum, descricao, dtInsercao, categoriasVO, photoVOs) : 
79                  new AlbumVO(nmalbum, descricao, dtInsercao, categoriasVO, photoVOs));
80          for (Iterator<PhotoVO> it = photoVOs.iterator(); it.hasNext();) {
81              PhotoVO photoVO = it.next();
82              photoVO.setAlbum(albumVO);
83          }
84          return albumVO;
85      }
86      
87  }